#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

vector<int> G[10005];
vector<int> GS[10005];
bool S[10005];
bool vis[10005];
int m, n;
int s, t;

bool check(int a) {
	for (int i = 0; i < G[a].size(); ++i) {
		if (!S[G[a][i]]) return 0;
	}
	return 1;
}

int bfs() {
	queue<pair<int, int> > q;
	q.push(make_pair(0, s));
	while (q.size()) {
		pair<int, int> x = q.front();
		q.pop();

		//printf("now:%d\n", x.second);

		if (x.second == t) {
			return x.first;
		}

		bool tp = vis[x.second];
		vis[x.second] = 1;
		if (!check(x.second)) continue;
		if (tp) continue;

		//printf("now:%d\n", x.second);

		for (int i = 0; i < G[x.second].size(); ++i) {
			if (S[G[x.second][i]]) {
				//printf("+%d-->%d\n", x.second, G[x.second][i]);
				q.push(make_pair(x.first + 1, G[x.second][i]));
			}
		}
	}
	return -1;
}

void choise_make() {
	queue<int> q;
	q.push(t);
	while (q.size()) {
		int now = q.front();
		q.pop();

		if (S[now]) continue;
		S[now] = 1;

		for (int i = 0; i < GS[now].size(); ++i) {
			if (!S[GS[now][i]]) q.push(GS[now][i]);
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);
	int x, y;
	for (int i = 1; i <= m; ++i) {
		scanf("%d %d", &x, &y);
		G[x].push_back(y);
		GS[y].push_back(x);
	}
	scanf("%d %d", &s, &t);

	/*
	for (int i = 1; i <= n; ++i) printf("%d ", G[i].size());
	printf("\n");
	*/

	choise_make();

	/*
	for (int i = 0; i <= n; ++i) printf("%d ", S[i]);
	printf("\n");

	for (int i = 0; i <= n; ++i) printf("%d ", check(i));
	printf("\n");
	*/

	printf("%d\n", bfs());
	return 0;
}